package com.vip.jwt.entity;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

/**
 * <p>
 * 角色权限关联表
 * </p>
 *
 * @author vip
 * @since 2021-05-04
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("t_role_permission")
@ApiModel(value="RolePermission对象", description="角色权限关联表")
public class RolePermission implements Serializable {

    private static final long serialVersionUID=1L;

    @ApiModelProperty(value = "ID")
    private String id;

    @ApiModelProperty(value = "角色ID")
    private String roleId;

    @ApiModelProperty(value = "权限ID")
    private String permissionId;

    /**
     * 根据关联表数据在列表中查找
     * @param permissions
     * @param rolePermissions
     * @return
     */
    public static List<Permission> findByIds(List<Permission> permissions, List<RolePermission> rolePermissions){
        List<Permission> newPermission = new ArrayList<>();
        for(int i=0;i<rolePermissions.size();i++){
            String id = rolePermissions.get(i).getPermissionId();
            for(int j=0;j<permissions.size();j++){
                Permission permission = permissions.get(j);
                boolean equals = StrUtil.equals(permission.getId(), id);
                if(equals){
                    newPermission.add(permission);
                    break;
                }
            }
        }
        return newPermission;
    }

}
